<div class="block_head">
    <div class="bheadl"></div>
    <div class="bheadr"></div>
    <h2>Tarefas</h2>
</div>
<div class="block_content">
    <?php
        if(!isset($this->data['Tarefa']['projeto)_id'])){
            $this->data['Tarefa']['projeto)_id'] = null;
        }
    echo $this->Form->create('Tarefa', array('url' => '/tarefas/index/' . $this->data['Tarefa']['projeto_id'])); ?>
    <p>
        <label>Adicione Tarefas:</label><br>
        <?php echo $this->Form->text('tarefa', array('class' => 'text big')); ?>
        <?php echo $this->Form->hidden('projeto_id'); ?>
    </p>
    <?php echo $this->Form->create('end'); ?>
        <br />
        <ul class="projetos">
            <li style="background-color:#a8ea9c !important;"><?php echo $this->Html->link('TODOS', '/tarefas/'); ?></li>
        <?php
        foreach ($projetos as $projeto) {
            $destaque = null;
            if($this->data['Tarefa']['projeto_id'] == $projeto['Projeto']['id']){
                $destaque = ' border: 2px solid #000000;';
            }
            //debug($destaque);
        
        ?>
            <li style="background-color: <?php echo $projeto['Projeto']['cor']; ?> !important;<?php echo $destaque; ?>"><?php echo $this->Html->link($projeto['Projeto']['nome'], '/tarefas/index/' . $projeto['Projeto']['id']); ?></li>
        <?php } ?>
    </ul>
    <br>
    <table width="100%" cellspacing="0" cellpadding="0">

        <tbody>
            <?php
            foreach ($tarefas as $t) {
                $class_ativa = '';
                $caractere = '>';
                if ($horaativa == $t['Tarefa']['id']) {
                    $class_ativa = 'ativo';
                    $caractere = '||';
                }
            ?>
                <tr class="<?php echo $class_ativa; ?>">
                    <!--td><input type="checkbox"></td-->
                    <td style="width: 90%;"><?php echo $t['Tarefa']['nome']; ?></td>
                <?php
                $deadline = '&nbsp;';
                if (isset($t['Tarefa']['deadline']) && $t['Tarefa']['deadline'] != null) {
                    $deadline = date('d/m/Y', strtotime($t['Tarefa']['deadline']));
                }
                ?>
                <td style="width: 90%;"><?php echo $deadline; ?></td>
                <td><?php echo $this->Html->link($caractere, '/tarefas/horas/' . $t['Tarefa']['id'], array('title' => 'INICIAR CONTAGEM DE TEMPO')); ?></td>
                <td><?php echo $this->Html->link('√', '/tarefas/completa/' . $t['Tarefa']['id'], array('title' => 'MARCAR COMO CONCLUIDO')); ?></td>
                <td><?php echo $this->Html->link('χ', '/tarefas/completa/' . $t['Tarefa']['id'] . '/DEL', array('title' => 'DELETAR'), 'Realmente deseja excluir esta tarefa?'); ?></td>
            </tr>
            <?php } //foreach Tarefas    ?>
        </tbody>
    </table>
</div>
<script type="text/javascript">
    $().ready(function() {

        function formatItem(row) {
            return row[0] + " (<strong>id: " + row[1] + "</strong>)";
        }
        function formatResult(row) {
            return row[0].replace(/(<.+?>)/gi, '');
        }

        $("#TarefaTarefa").autocomplete(cities, {
            multiple: true,
            mustMatch: false,
            autoFill: true,
            width: 310,
            multipleSeparator: ' '
        });
    });
    var cities = [
<?php
            foreach ($projetos as $p) {
                echo '"' . '#' . $p['Projeto']['nome'] . ';' . '",';
            }
            foreach ($usuarios as $id => $nome) {
                echo '"' . '@' . $nome . ';' . '",';
            }
            foreach ($clientes as $id => $nome) {
                echo '"' . '%' . $nome . ';' . '",';
            }
?>

    ];
</script>